package serveur;

import java.net.InetAddress;
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;

import modele.Bd;


public class ServeurImpl extends  UnicastRemoteObject implements Serveur {
    /**
	 * 
	 */
	private static final long serialVersionUID = 2L;
	// les parametres du serveur
    private String host;
    private String port;
    private String service;
    private int nbClients;

    // La base de données de l'application
    private Bd     bd     = null;

    public ServeurImpl(String numPort) throws Exception{
	super();
	host = InetAddress.getLocalHost().getHostName();
	port = numPort;
	service = "Master";
	String name = "rmi://" + host+":"+port+"/"+service;
	LocateRegistry.createRegistry(Integer.decode(port));
	Naming.rebind(name, this);
	nbClients = 0;
    }

    // pour avoir de l'info sur le service
    public String getHost()	 throws Exception {return host;}
    public String getPort()	 throws Exception {return port;}
    public String getService() 	 throws Exception {return service;}
    public int    getNbClients() throws Exception {return nbClients;}
    public void AddClient() throws Exception {nbClients++;}
    public void RemoveClient() throws Exception {nbClients--;}

    // implementation de Serveur
    public Bd     getBd()       throws Exception {return bd;}
    public void   setBd(Bd bd)  throws Exception {this.bd = bd;}
}
